CP=cp
GZIP=gzip
DPKG=dpkg-deb
FAKEROOT=fakeroot

all:
	$(MAKE) deb
	$(MAKE) tgz
	
tgz:
	tar cfz out/simple-backup-0.1.tar.gz src/scripts/* src/doc/*		

deb: out/*.deb

out/*.deb: out/build/DEBIAN/control out/build/usr/bin/simple-backup out/build/usr/share/man/man1/simple-backup.1.gz
	${FAKEROOT} ${DPKG} --build out/build out/

out/build/DEBIAN/control: src/deb/control
	$(MAKE) prepare
	${CP} src/deb/control out/build/DEBIAN

out/build/usr/bin/simple-backup: src/scripts/simple-backup
	$(MAKE) prepare
	${CP} src/scripts/simple-backup out/build/usr/bin/simple-backup

out/build/usr/share/man/man1/simple-backup.1.gz: out/build/usr/share/man/man1/simple-backup.1
	$(MAKE) prepare
	${GZIP} -f out/build/usr/share/man/man1/simple-backup.1

out/build/usr/share/man/man1/simple-backup.1: src/doc/simple-backup.1
	$(MAKE) prepare
	${CP} src/doc/simple-backup.1 out/build/usr/share/man/man1/simple-backup.1

clean:
	rm -rf out
	
prepare:
	mkdir -p out/build/DEBIAN
	mkdir -p out/build/usr/bin
	mkdir -p out/build/usr/share/man/man1
